package com.cyzy.service.impl;

import com.cyzy.dao.DistributionApplicationDao;
import com.cyzy.mapper.DistributionMapper;
import com.cyzy.pojo.*;
import com.cyzy.service.DistributionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DistributionServiceImpl implements DistributionService {
    @Autowired
    private DistributionMapper distributionMapper;

    @Override
    public User getUser(Long userId) {
        return distributionMapper.getUser(userId);
    }

    @Override
    public CourseParent getParent(Long parentId) {
        return distributionMapper.getParent(parentId);
    }

    @Override
    public DistributionApplicationDao selectUser(Long userId) {
        return distributionMapper.selectUser(userId);
    }

    @Override
    public DistributionApplicationDao selectParent(Long parentId) {
        return distributionMapper.selectParent(parentId);
    }

    @Override
    public DistributorApp exitUser(DistributorApp distributorApp){
        return distributionMapper.existUser(distributorApp);
    }

    @Override
    public void insertDistributionApp(DistributorApp distributorApp){
        int exit = distributionMapper.insertDistributionApp(distributorApp);
        if (exit > 0){
            DistributorIncome distributorIncome = new DistributorIncome();
            distributorIncome.setUserId(distributorApp.getUserId());
            distributorIncome.setParentId(distributorApp.getParentId());
            distributorIncome.setCampusId(distributorApp.getCampusId());
            distributorIncome.setDistributorName(distributorApp.getUserName());
            distributionMapper.insertDistributorIncome(distributorIncome);
        }
    }

    @Override
    public void schoolDistributionApp(Campusdistriapply campusdistriapply){
         distributionMapper.schoolDistributionApp(campusdistriapply);
    }

    @Override
    public Campusdistriapply exitCampusApp(Campusdistriapply campusdistriapply){
        return distributionMapper.exitCampusApp(campusdistriapply);
    }
}
